home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 July / Macworld (1999-07).dmg / Serious Software / OpenWorld demo 2.0 / Development / Headers / WSAPI.h < prev   
Text File  |  1998-08-09  |  40KB  |  740 lines

  1. //WSAPI.h
  2.  
  3. /*
  4. WebSTAR API Interface, v1.1
  5. Copyright ©1996, StarNine Techologies, Inc. All rights reserved.
  6.  
  7. This file defines the public interface between the WebSTAR plug-in framework and
  8. user-defined plug-in routines.
  9.  
  10. */
  11.  
  12. #ifndef WSAPI_Included
  13. #define WSAPI_Included 1
  14.  
  15. #if GENERATINGPOWERPC
  16. #pragma options align=mac68k
  17. #endif
  18.  
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22.  
  23. #define WSAPI_VERSION    (unsigned long) 0x01010000    //Do NOT modify this value
  24. #define WSAPI_MAC    1
  25.  
  26.  
  27. #include <AppleEvents.h>
  28.  
  29. extern unsigned long wsapi_lib_version;    // the version of the WSAPI library code this plug-in is linked with. Useful
  30.                                         // for making sure your plug-in was built with libs that match the interfaces, etc.
  31.  
  32.  
  33. // enums that identify what type of server is "glued" to the WSAPI plug-in. Useful for determining the callback
  34. // and parameter feature set that will be available at run-time. See wsapi_glue_type variable below.
  35. typedef enum {
  36.     WSAPI_Mac_Glue,        //plug-in is built as a WebSTAR Mac plug-in
  37.     WSAPI_PC_Glue,        //plug-in is built as a WebSTAR 95 or NT plug-in
  38.     NSAPI_Glue,            //plug-in is built as a Netscape plug-in
  39.     ISAPI_Glue            //plug-in is built as a Microsoft plug-in
  40. } WSAPI_Server_Glue_Type;
  41.  
  42. extern WSAPI_Server_Glue_Type wsapi_glue_type;    //what type of glue libraries are being used by the plug-in?
  43.  
  44. #define WSAPI_NAME_SIZE    32
  45. #define WSAPI_FILE_NAME_SIZE     256            /*size of text representations of file paths*/
  46. #define WSAPI_VERSION_STR_SIZE    12            /*size of the version string returned in the init message pb*/
  47. #define WSAPI_INDEX_SIZE 64                    //the maximum length of index selectors used with Get and SetIndexedParameter
  48.  
  49. #define WSAPI_IPC_CONNECTION_MASK 0x00003FFF //See WSAPI_SendIPCMessage below
  50.  
  51. //  Not completely implemented yet. You may set these flags, but WebSTAR ignores them for now.
  52. //  Flags that define capabilities that the plug-in can perform or services it wants to take advantage of
  53. //  Used in the "capabilities" field of the Init message's PB record. Your plug-in should OR the appropriate
  54. //  flags together and assign them to the capabilities field which is returned to the server at the completion of the
  55. //    Init message handling. The server will use these flags to determine if a user has misconfigured your plug-in for
  56. //    a role that it cannot support.
  57.  
  58. #define capISAPISubset        (unsigned long) 0x00000001        //restrict plug-in to ISAPI compatible calls - not implemented yet
  59. #define capCGI                (unsigned long) 0x00000002        //plug-in is willing to operate as a normal CGI plug-in
  60. #define capPreProcessor        (unsigned long) 0x00000004        //p.i. will work as a preprocessor
  61. #define capPostProcessor    (unsigned long) 0x00000008        //p.i. will work as a postprocessor
  62. #define capLogging            (unsigned long) 0x00000010        //p.i. will receive logging and status messages - not implemented yet
  63. #define capSecurity            (unsigned long) 0x00000020        //p.i. will perform security checks - not implemented yet
  64. #define capNSAPISubset        (unsigned long) 0x00000040        //restrict plug-in to NSAPI compatible calls - not implemented yet
  65.  
  66. /*****************************************************************************/
  67. /*##     Important note to developers: Not all servers will implement all of these parameters.
  68.         It is up to individual server implementors to decide which parameters will be supported,
  69.         since some of these are WebSTAR-specific. It is possible that other server implementors
  70.         will add additional parameters beyond the ones supported by WebSTAR as well.
  71.  */
  72.  
  73. /** Keywords used to get/set WebSTAR parameters with WSAPI_Get/SetParameter **/
  74. /** Note that these have the same definitions and formats as AppleEvent parameters
  75.     of the same value. With the exceptions noted below, all parameters are of type
  76.     "typeChar." The two numeric values below should be noted.
  77. **/
  78. typedef enum {
  79.     piPathArgKeyword        = '----',
  80.     piSearchArgKeyword        = 'kfor',
  81.     piUserKeyword            = 'user',
  82.     piPasswordKeyword        = 'pass',
  83.     piFromUser                = 'frmu',
  84.     piAddressKeyword        = 'addr',
  85.     piPostKeyword            = 'post',
  86.     piMethodKeyword            = 'meth',
  87.     piServerName            = 'svnm',
  88.     piServerPort            = 'svpt',    //typeShortInteger - IP port (e.g, 80)
  89.     piScriptName            = 'scnm',
  90.     piContentType            = 'ctyp',
  91.     piContentLength            = 'CLen',    //typeLongInteger - the content-length header field (if any) from HTTP request
  92.     piRefererKeyword        = 'refr',
  93.     piUserAgentKeyword        = 'Agnt',
  94.     piActionKeyword            = 'Kact',
  95.     piActionPathKeyword        = 'Kapt',
  96.     piClientIPAddress        = 'Kcip',    //typeLongInteger - 4 byte IP address
  97.     piFullRequestKeyword    = 'Kfrq',
  98.     
  99.     //new for plug-ins only
  100.     piFileMIMEType            = 'Mime',    // The MIME type of the URL in piScriptName
  101.     piServerField            = 'SvFd',    // The HTTP header field for this server. e.g., "Server: WebSTAR/1.3 ID/22"
  102.     piServerDirectoryPath    = 'SPth',    // A C string representing the complete (machine-specific) path name of the server's working directory
  103.     piURLPhysicalPath        = 'UPth',    // If the URL represents an actual file in the file system, this parameter contains its name relative to the server's root.
  104.     piIfModifiedSince        = 'IfMS',    // short. True if the file has been modified since last retrieval or if modification cannot be determined. False if unchanged.
  105.     piIfModifiedDate        = 'IfMD',    //## typeChar, R/O, if-modified-since date string from HTTP request header
  106.     piCurrentRealm            = 'CRlm',    // typeChar, 256 max. The realm (if any) that the requested URL belongs to.
  107.                                         // WSAPI_E_RequestFailed will be returned by GetParameter if this value isn't defined for the current request.
  108.     piURLFileRef            = 'Pufr',    //## typeFSS, R/0, Server-specific reference to file in the native O/S. On the
  109.                                         //  Mac with WebSTAR, this is a FSSpec to actual file being requested if it
  110.                                         //  really exists on disk. Nonexistent files will have a FSSpec that has all
  111.                                         //  fields set to zero and the name field will be empty.    
  112.     //******************************
  113.     //log- and status-related values
  114.     piConnectionID            = 'LCID',    //long - unique # for each connection for this run of the server
  115.     piServerUniqueID        = 'LSID',    //long - unique # across all current server invocations on this machine
  116.     // note: the value of the WebSTAR message-id: field can be generated with the following C printf format,
  117.     //   using the values of the preceding two properties:
  118.     //  printf ("<%0lx.%ld@%s>", serverUniqueIDVar, connectionIDVar, hostnameVar);
  119.     
  120.     //*****************************
  121.     // The following parameters are read-only and represent information present in the server's 
  122.     // status display and/or the information broadcast to remote logging processes.
  123.     piTotalConnections        = 'STCn',    // long. Total connections the server has received since it started up
  124.     piCurrentUserLevel        = 'SCLd',    // short. Current number of users connected to the server at this time
  125.     piHighestUserLevel        = 'SMLd',    // short. Max number of users ever connected to the server at once
  126.     piCurrentFreeMemory        = 'SFMm',    // long. Amount of free memory available to the server process
  127.     piMinimumFreeMemory        = 'SMFM',    // long. Minimum amount of free memory that was ever available to the server process
  128.     piTotalConTimeouts        = 'STTm',    // short. Total number of client connections that timed out before completion
  129.     piTotalConBusies        = 'STBz',    // short. Total number of client connections refused because the server was too busy
  130.     piTotalConDenied        = 'STDn',    // short. Total number of client connections denied by domain name or IP address
  131.     piTotalBytesSent        = 'TByt',    // long. Total number of bytes sent by the server
  132.     piUpSinceDate            = 'SUpS',    // C string. Date & time the server was launched; Format, MM/DD/YY:HH:MM
  133.     piPluginAdminInfo        = 'Padm',    //##typeChar, R/O, text block containing info on each plug-in currently installed
  134.                                         //    tab separated syntax of each line is: <name> <version> <Admin URL path><cr>
  135.     
  136.     //******************************
  137.     // ##These four parameters describe the plug-in environment, including the physical location of plug-ins
  138.     // and information about each parameter that can be manipulated at runtime to determine range checks, types,
  139.     // string representations, etc. See the W*API docs for details on the format of the piPluginParamInfo data structure.
  140.     
  141.     piPluginParamInfo        = 'Pipi',    //##typeLong, R/O, pointer to a W*API-specific data structure describing plug-in parameter semantics
  142.     piPluginParamCount        = 'Pipc',    //##typeSMInt, R/O, count of the number of W*API parameters in piPluginParamInfo
  143.     piPluginDirPath            = 'Pdph',    //##typeChar, R/O, full path to the plug-ins folder
  144.     piPluginDirFSSpec        = 'Pdfs',    //##typeFSS, R/O, platform-specific file system reference to plug-ins folder
  145.     
  146.     //******************************
  147.     //the following 3 values are only guaranteed to be set AFTER a connection has been completed
  148.     //  and logged. (i.e., only access them from a post-processor plug-in.)
  149.     piTransferResult        = 'LTRs',    //OK, PRIV, or ERR! string, depending on transfer result
  150.     piBytesSent                = 'LByt',    //number of bytes written to the HTTP client
  151.     piTransferTime            = 'LTrT',    //number of ticks it took from connection open to close
  152.     
  153.     //******************************
  154.     // WebSTAR properties below here.
  155.     //  These match the definitions in the WebSTAR AETE resource.
  156.     
  157.     // The following values are all global WebSTAR properties.
  158.     
  159.     piDumpBufSize            = 'Dbuf',    //typeLongInteger
  160.     piPigDelay                = 'PigD',    //typeSMInt
  161.     piMaxUsers                = 'MaxU',    //typeSMInt
  162.     piNoDNS                    = 'Ndns',    //typeSMInt
  163.     piTimeOut                = 'TimO',    //typeSMInt
  164.     piMaxListens            = 'MaxL',    //typeSMInt
  165.     piLogging                 = 'Plog',    //typeSMInt
  166.     piVerboseMessages        = 'Pvrb',    //typeSMInt
  167.     piRefuseConnections        = 'Pcon',    //typeSMInt
  168.     piHideWindow            = 'Phid',    //typeSMInt
  169.     piDefaultMIMEType        = 'Pmim',    //typeChar
  170.     piPort                    = 'Pprt',    //typeSMInt
  171.     piIndexFile                = 'Pixf',    //typeChar
  172.     piErrorFile                = 'Perf',    //typeChar
  173.     piLogFile                = 'Plgf',    //typeChar
  174.     piNoAccessFile            = 'Pnaf',    //typeChar
  175.     piSuffixMappings        = 'Psuf',    //typeChar
  176.     piAllowDeny                = 'Pa/d',    //typeChar
  177.     piAllowDenyByRealm        = 'PADr',    //##typeChar - R/W, NOTE!! This is an indexed value and you must use the
  178.                                         // WSAPI_GetIndexedParameter or WSAPI_SetIndexedParameter call to manipulate it. The Index is
  179.                                         // the name of the realm to get or set allow/deny info for.
  180.     piRealms                = 'Prlm',    //typeChar
  181.     piActions                = 'Pact',    //typeChar
  182.     piLogFormat                = 'Plfm',    //typeChar
  183.     piPreProcessor            = 'Ppre',    //typeChar
  184.     piPostProcessor            = 'Ppst',    //typeChar
  185.     piVersionNumber            = 'Pvrs',    //typeChar
  186.     piReportDelay            = 'Prdl',    //##typeSMInt - R/W, amount of time in seconds between status report events
  187.     piCacheFlush            = 'Pcfl',    //##typeSMInt - W/O, setting this flag indicates the server should flush any
  188.                                         // cached data. A plug-in receiving this parameter to a WSAPI_ServerStateChanged
  189.                                         // message should interpret it as a signal for the plug-in to flush any cached data
  190.                                         // it retains from the local file system.
  191.     piFileInfoCacheSize        = 'Pfic',    //##typeLong - R/W, amount of memory to allocate to file info caching
  192.     piKeepAliveConnections    = 'Pkac',    //##typeSMInt- R/W, number of connections per client to keep alive
  193.     piKeepAliveTime            = 'Pkat',    //##typeSMInt- R/W, seconds to keep alive idle client connections
  194.     piServerCName            = 'Pscn',    //##typeChar - R/W, canonical name of server to be used in HTTP responses, regardless of DNS name
  195.     piCGIBinOnly            = 'Pcbo',    //##typeSMInt - R/W, flag determining if CGIs will be executed from the /cgi-bin folder only
  196.     piServiceAddress        = 'Pisa'    //##typeLong - R/W, INDEXED VALUE, table of registered service addresses
  197.                                         // This is a complicated parameter. You should refer to the W*API documentation for details.
  198.                                         // The index is the name of the service whose address you wish to register or retrieve.
  199. } WSAPI_ParamKeywords;
  200.             
  201. /*****************************************************/
  202. //    Parameter block information
  203.  
  204. typedef unsigned long WSAPI_Stream, *WSAPI_StreamPtr; //type for IP callbacks in network stuff below
  205.  
  206. //messages sent to plug-in dispatcher
  207. typedef enum {
  208.     WSAPI_Init, 
  209.     WSAPI_Shutdown, 
  210.     WSAPI_Idle, 
  211.     WSAPI_Run, 
  212.     WSAPI_Emergency, 
  213.     WSAPI_ServerStateChanged, 
  214.     WSAPI_Register,
  215.     WSAPI_AccessControl,    //##
  216.     WSAPI_Filter            //##
  217. } WSAPI_Command;
  218.  
  219. //sub-messages sent to plug-in dispatcher in the "role" field when message is "WSAPI_Run"
  220. typedef enum {
  221.     WSAPI_CGI_Role,                //running as a normal CGI replacement
  222.     WSAPI_PreProcessor_Role,    //acting as a pre-processor
  223.     WSAPI_PostProcessor_Role,    //acting as a post-processor
  224.     WSAPI_Logging_Role,            //receiving log info
  225.     WSAPI_Security_Role,        //performing an access authorization
  226.     WSAPI_Error_Role,            //handling bad URL requests
  227.     WSAPI_NoAccess_Role,        //handling requests denied by IP or domain
  228.     WSAPI_Index_Role            //handing a request for the default file
  229. } WSAPI_Run_Role;
  230.  
  231. //descriptor type used to extract various named parameters available to plug_ins
  232. typedef void *WSAPI_DescPtr;
  233.  
  234. /** structure types making up the CommandPB parameter block **/
  235.  
  236. typedef struct {        // now used by both init and register messages
  237.     short resRef;        //in - reference number of plug-in's resource file
  238.     char pluginName [WSAPI_NAME_SIZE]; //##in/out - the unique name that identifies this plug-in. Initialized to file name.
  239.     unsigned long capabilities; // out - flags that indicate functions the plug-in can perform or services it wants
  240.     //## these fields should be filled in during the Register message
  241.     char version [WSAPI_VERSION_STR_SIZE]; //##out - string representation of the plug-in's version, e.g., "1.0b1"
  242.     char adminURL [WSAPI_FILE_NAME_SIZE]; //##out - path portion ONLY of URL to configure plug-in, e.g. "/admin.plugsuffix"
  243. } WSAPI_InitPB;
  244.  
  245. typedef struct {
  246.     short unused;         //not sure what args shutdown needs to send in and out yet
  247. } WSAPI_ShutdownPB;
  248.  
  249. typedef struct {
  250.     unsigned long ticksToSleep;    //out - how long to sleep before WebSTAR's idle handler calls again
  251. } WSAPI_IdlePB;
  252.  
  253. typedef struct {
  254.     WSAPI_Run_Role role;    //what is this invocation supposed to do? be a CGI, preprocessor, etc?
  255. } WSAPI_RunPB;
  256.  
  257. typedef struct {
  258.     short unused;
  259. } WSAPI_EmergencyPB;
  260.  
  261. typedef struct {
  262.     WSAPI_ParamKeywords    whichParam;        // contains the WSAPI_ParamKeywords (parameter) value that has changed
  263. } WSAPI_StateChangedPB;
  264.  
  265. typedef struct {
  266.     short    grantAccess;        //## boolean flag. If true, the server will process the URL as normal
  267.     short    authRequired;        //## boolean flag. If true, the server will require password access
  268. } WSAPI_AccessControlPB;
  269.  
  270. typedef struct {                //## server sends this structure with the WSAPI_Filter message
  271.     char *request;                //## request contains a pointer to the read-only HTTP request data (not including object body)
  272.     short requestLength;        //## length in characters of the request. Data beyond length bytes should not be modified!
  273.     char *newRequest;            //## null initially. setting pointer to new request data (allocated by you with WSAPI_AllocateMemory ONLY!)
  274.                                 //##   forces server to replace original request with data you generate for the request instead
  275.     short newRequestLength;        //## zero initially. length in characters of the new request you create.
  276. } WSAPI_FilterPB;
  277.  
  278. typedef union {
  279.     WSAPI_InitPB         init;            // used by both register and init messages
  280.     WSAPI_ShutdownPB     shutdown;
  281.     WSAPI_IdlePB        idle;
  282.     WSAPI_RunPB            run;
  283.     WSAPI_EmergencyPB    emergency;
  284.     WSAPI_StateChangedPB stateChanged; // see above
  285.     WSAPI_AccessControlPB accessControl; //##
  286.     WSAPI_FilterPB        filter; //##
  287. } WSAPI_PB_Union;
  288.  
  289. typedef struct {
  290.     long api_version;            //in - what version of API does the server support?
  291.     void *api_data;                //in - private data. DON'T TOUCH!
  292.     WSAPI_Command command;        //in - what operation is the plug-in to perform?
  293.     WSAPI_PB_Union param;
  294. } WSAPI_CommandPB, *WSAPI_CommandPBPtr;
  295.  
  296. // record for holding pending IPC stuff
  297. #if WSAPI_MAC
  298.  
  299. typedef struct {
  300.     AppleEvent theAppleEvent;
  301.     AppleEvent reply;
  302.     long handlerRefcon;
  303. } WSAPI_IPC_Result, *WSAPI_IPC_ResultPtr;
  304.  
  305. #else
  306.  
  307. typedef struct {
  308.     void *theIPCMsg;
  309. } WSAPI_IPC_Result, *WSAPI_IPC_ResultPtr;
  310.  
  311. #endif
  312.  
  313. //*******************************
  314. //##Definitions for the piPluginParamInfo data structure
  315.  
  316. #define WSAPI_PARAM_SIZE 32
  317.  
  318. typedef struct piparam_table_struct {
  319.     WSAPI_ParamKeywords param;        //one of the enums from above
  320.     char name[WSAPI_PARAM_SIZE];    //case-sensitive string representation of the parameter's name
  321.     char index[WSAPI_PARAM_SIZE];    //"name" of the index field. usually maps to a HTML form field name
  322.     OSType type;                    //4 character (long) parameter type
  323.     short mode;                        //bit field describing read/write access. masks: read = 2, write = 1
  324.     long lower;                        //lower bound for range checking integer parameters
  325.     long upper;                        //upper bound for range checking. If less than lower bound, no range is specified
  326.     void *extra_info;                //reserved for future expansion
  327. } WSAPI_ParamInfo, *WSAPI_ParamInfoPtr;
  328.  
  329.  
  330. //*******************************
  331. /** Error codes returned by various WSAPI calls **/
  332.  
  333. typedef enum {
  334.     WSAPI_I_NoErr,                //normal completion code, synonymous with noErr
  335.     WSAPI_E_MessageNotHandled,    //return value indicates the command message wasn't processed
  336.     WSAPI_E_ParameterNotFound,    //requested parameter descriptor did not exist
  337.     WSAPI_E_InsufficientMemory,    //not enough memory to perform requested operation
  338.     WSAPI_E_Unimplemented,        //requested function is not yet implemented or isn't available for this version of WSAPI
  339.     WSAPI_E_HTTPConnectionGone,    //the client connected to this thread has closed the connection
  340.     WSAPI_E_BadCommandPtr,        //commandPtr that was passed was null or invalid
  341.     WSAPI_E_CantOpenStream,        //TCP/IP stream couldn't be created or opened
  342.     WSAPI_E_BufferTooBig,        //data buffer was too large for the callback to process
  343.     WSAPI_E_NameLookupFailed,    //the domain name resolver failed to resolve the requested name
  344.     WSAPI_E_NullDescriptor,        //10, a null descriptor, or one with no data pointer was passed when real data was required
  345.     WSAPI_E_UnspecifiedError,    //some unknown error happened
  346.     WSAPI_E_BadArgument,        //one of the arguments (usually a pointer) passed to a callback was invalid
  347.     WSAPI_E_CantModifyData,        //an attempt was made to modify read-only data
  348.     WSAPI_E_DescriptorTooSmall,    //user-supplied storage for a descriptor is too small for the data being assigned to it
  349.     WSAPI_E_HTTPConnectionErr,    //plug-in attempted to read from a closed or non-existent HTTP stream, or some other IP-related error occurred.
  350.     WSAPI_E_WrongRoleForCall,    // plug-in tried to make a callback that is inappropriate for the current WSAPI_Command
  351.     WSAPI_E_RequestFailed,        // whatever request the plug-in was making of the server failed to complete successfully
  352.     WSAPI_E_IPCMsgPending,        // an attempt was made to send an IPC message while one was already in progress
  353.     WSAPI_E_IPCNoMsgPending,    // an attempt was made to receive IPC message results when no message was in progress
  354.     WSAPI_E_Timeout,            //20, requested operation took too long and timed out before being completed
  355.     WSAPI_I_NoPermission,        // current user doesn't have permissions for realm; other security violation
  356.     WSAPI_E_ParameterIndexedOnly,//the requested parameter can only be accessed as an indexed parameter
  357.     WSAPI_E_IndexedValueNotFound//the item specified by the index was not present in the requested object
  358. } WSAPI_ErrorCode;
  359.  
  360. /** TCP/IP conection status codes **/
  361.  
  362. typedef enum {
  363.     WSAPI_IP_Closed,     //connection is closed or terminated. plug-in should stop processing
  364.     WSAPI_IP_Open,         //connection is open
  365.     WSAPI_IP_Data,        //connection is open and has unread data on it
  366.     WSAPI_IP_Unknown    //an unknown or unspecified error occurred
  367. } WSAPI_ConnectionStatus;
  368.  
  369. /** ##Misc. W*API type definitions **/
  370.  
  371. typedef char WSAPI_IndexString [WSAPI_INDEX_SIZE];    //index selector used by WSAPI_Get and SetIndexedParameter
  372. typedef WSAPI_IndexString *WSAPI_IndexStringPtr;
  373.  
  374. /********************************************************************/
  375. //WSAPI Framework Function prototypes
  376.  
  377. // You may call any of the following functions from inside your plug-in to 
  378. // have WebSTAR perform the requested function.
  379.  
  380. /*************************/
  381. /**  Memory Management  **/
  382.  
  383. void *WSAPI_AllocateMemory (WSAPI_CommandPBPtr pb, long size);
  384. /*     Allocates and returns a pointer to "size" bytes of data. Returns NULL if
  385.     memory allocation fails.
  386.     Do NOT use any other techniques to allocate memory within your plug-in code.
  387.     All memory should be allocated using this call and disposed of using the 
  388.     corresponding WSAPI_FreeMemory call.
  389. */
  390.  
  391. void WSAPI_FreeMemory (WSAPI_CommandPBPtr pb, void *data);
  392. /*    Deallocates a block of memory originally allocated with WSAPI_AllocateMemory. Do NOT mix
  393.     and match WSAPI_AllocateOSMemory and WSAPI_FreeMemory or vice versa!!!
  394. */
  395.  
  396. void *WSAPI_AllocateOSMemory (WSAPI_CommandPBPtr pb, long size);
  397. /*      Allocates and returns an O/S-specific memory accessor (e.g., a Handle under Mac O/S)
  398.     to "size" bytes of data. Returns NULL if memory allocation fails.
  399.     Do NOT use any other techniques to allocate memory within your plug-in code.
  400.     All memory should be allocated using this call and disposed of using the 
  401.     corresponding WSAPI_FreeOSMemory call.
  402. */
  403.  
  404. void WSAPI_FreeOSMemory (WSAPI_CommandPBPtr pb, void *data);
  405. /*     Deallocates a block of memory originally allocated with WSAPI_AllocateOSMemory. Do NOT mix
  406.     and match WSAPI_AllocateMemory and WSAPI_FreeOSMemory or vice versa!!!
  407. */
  408.  
  409. /*************************/
  410. /** Process Management  **/
  411.  
  412. WSAPI_ErrorCode WSAPI_YieldTime (WSAPI_CommandPBPtr pb, long ticksToYield);
  413. /*    Yields time to WebSTAR, allowing other threads, plug-ins, and processes to
  414.     have access to the CPU. ticksToYield is only a suggestion to WebSTAR about how
  415.     long to wait (in ticks) before resuming this thread. Control may return sooner or later
  416.     than the time specified. This routine MUST be called if you are performing any
  417.     processing that takes more than a few milliseconds, involves I/O of any significant
  418.     amount, or would otherwise prevent normal operation of other apps in the
  419.     MultiFinder environment. This call is essentially equivalent to the Thread Manager's
  420.     YieldToAnyThread call.
  421. */
  422.  
  423. WSAPI_ErrorCode WSAPI_RequestIdleTime (WSAPI_CommandPBPtr pb, unsigned long ticksToSleep);
  424. /*    This routine registers your plug-in with WebSTAR's idle time dispatcher. Plug-ins
  425.     registered this way will have the WSAPI_Idle command sent to them at an interval
  426.     approximating ticksToSleep. Plug-ins are called in the context of the idle dispatcher
  427.     and will not have access to an active HTTP connection or associated data.
  428.     This routine is useful for performing periodic global tasks within your plug-in.
  429. */
  430.  
  431. /*************************/
  432. /** Networking Services **/
  433.  
  434. WSAPI_ErrorCode WSAPI_SendHTTPData (WSAPI_CommandPBPtr pb, void *data, long dataLen);
  435. /*    Sends an arbitrarily large buffer of data to a HTTP client over an open HTTP connection.
  436.     This implements a raw data stream to the client, allowing you to generate your own HTTP 
  437.     header and content, similar to what current CGI applications do now. The difference is
  438.     that your data is going back in real time and you can send as much as you'd like.
  439.     "data" is a pointer to a buffer containing any type of data. dataLen is the number of 
  440.     bytes within this buffer to transmit. No translation is performed by WebSTAR on data. 
  441.     You are responsible for disposing of the data pointer after this call returns, if 
  442.     necessary. Avoid sending many, small buffers of data with this routine if possible.
  443.     
  444.     NOTE: If this call ever returns a non-zero return value, you should terminate any
  445.     processing and return control to WebSTAR immediately. This is an indication 
  446.     that the client has disconnected and WebSTAR needs to clean up the connection.
  447. */
  448.  
  449. WSAPI_ErrorCode WSAPI_ReadHTTPData (WSAPI_CommandPBPtr pb, void *data, long *dataLen);
  450. /*    Reads data from the HTTP stream. Useful for reading and processing large POST args,
  451.     etc., like file uploads. You must supply storage for data and pass in the maximum amount of
  452.     data to be returned in the dataLen parameter. WSAPI will return up to dataLen bytes in data
  453.     and will set dataLen to the actual amount of data returned. 
  454.     
  455.     Use the WSAPI_HTTPConnectionStatus below to determine if data is pending on the HTTP connection, etc.
  456.     
  457.     IMPORTANT! If a pre-processor reads the HTTP object body data from a connection, that data
  458.     will NOT be available to downstream plug-ins or CGIs should the pre-processor decide not to
  459.     handle the URL. That means no post args for CGIs, etc. In general, it's bad form for any
  460.     role other than CGI, Error, NoAccess, or Index to make this call. Specific cases excepted.
  461.     
  462.     Additional note, the piPostKeyword parameter can be used to repeatedly access the first 24k bytes
  463.     of this data without any side effects to downstream consumers or the IP data stream.
  464. */
  465.  
  466. WSAPI_ErrorCode WSAPI_HTTPConnectionStatus (WSAPI_CommandPBPtr pb, WSAPI_ConnectionStatus *status);
  467. /*    Returns the status of the HTTP connection associated with the thread that this call is made
  468.     from. Obviously, this is an invalid call to make from any message handler except the RUN 
  469.     message. Returns the appropriate WSAPI_ConnectionStatus in the status parameter.
  470. */
  471.     
  472. //Generic Open, Close, Send, and Receive - TBS
  473.  
  474. WSAPI_ErrorCode WSAPI_OpenStream (WSAPI_CommandPBPtr pb, WSAPI_StreamPtr stream, unsigned long ip_addr, unsigned short ip_port);
  475. /*
  476.     Returns a Stream pointer to an open connection to the host and port specified. ip_addr is a
  477.     long integer representation of the host address, as returned from the DNS routines. If an error is returned,
  478.     the stream was not successfully created.
  479. */
  480.  
  481. WSAPI_ErrorCode WSAPI_CloseStream (WSAPI_CommandPBPtr pb, WSAPI_StreamPtr stream);
  482. /*
  483.     Gracefully closes a connection opened using OpenStream.
  484. */
  485.  
  486. WSAPI_ErrorCode WSAPI_ReadStream (WSAPI_CommandPBPtr pb, WSAPI_StreamPtr stream, void *data, long *dataLen);
  487. /*
  488.     Reads up to *dataLen bytes from the specified stream. *dataLen contains the actual number of bytes read,
  489.     which may be less than the number requested.
  490. */
  491.  
  492. WSAPI_ErrorCode WSAPI_WriteStream (WSAPI_CommandPBPtr pb, WSAPI_StreamPtr stream, void *data, long dataLen);
  493. /*
  494.     Writes dataLen bytes of data to the specified stream. If dataLen is too large, an error will be returned.
  495.     Generally, you should never try to write more data than the maximum dump_buf_size for WebSTAR in one operation.
  496. */
  497.  
  498. WSAPI_ErrorCode WSAPI_StatusStream (WSAPI_CommandPBPtr pb, WSAPI_StreamPtr stream, WSAPI_ConnectionStatus *status, long *pending);
  499. /*
  500.     Returns the status of the specified stream (open, closed, data pending) and the amount of unread data. Under
  501.     OpenTransport, the pending flag will simply be positive if data exists to be read.
  502. */
  503.  
  504. WSAPI_ErrorCode WSAPI_IPNameToAddr (WSAPI_CommandPBPtr pb, char *name, unsigned long *addr);
  505. /*
  506.     Converts the domain name or dotted IP address in "name" into a 4 byte IP address for use in the OpenStream call.
  507. */
  508.  
  509.  
  510. /*************************/
  511. /**  Utility Functions  **/
  512.  
  513. WSAPI_ErrorCode WSAPI_GetParameter (WSAPI_CommandPBPtr pb, WSAPI_ParamKeywords whichParam, 
  514.                                     WSAPI_DescPtr *descriptor);
  515. /*    Use this routine to obtain descriptors that reference named WebSTAR data elements. These
  516.     elements are generally equivalent to the AppleEvent parameters passed to CGIs. However,
  517.     certain WebSTAR properties will also be made available via this interface. See the list
  518.     of available parameters and properties above (WSAPI_ParamKeywords).
  519.     
  520.     You must always dispose of any descriptors returned by WSAPI_GetParameter.
  521.     
  522.     If the value for a parameter is undefined at the time the call is made, but the paramter is a legal
  523.     one to request, WSAPI_GetParamter will return WSAPI_E_RequestFailed. If the parameter cannot be requested
  524.     at the time the call is made (because of role or message conflicts), the WSAPI_E_WrongRoleForCall error
  525.     will be returned.
  526.     
  527. */
  528.  
  529. WSAPI_ErrorCode WSAPI_SetParameter (WSAPI_CommandPBPtr pb, WSAPI_ParamKeywords whichParam, 
  530.                                     WSAPI_DescPtr descriptor);
  531. /*     Use this routine to set server parameters to the value specified in the descriptor.
  532.     You need to create the descriptor first, using WSAPI_NewDescriptor. Then use WSAPI_SetDescriptor
  533.     to insert values into the new descriptor before passing it to WSAPI_SetParameter.
  534. */
  535.  
  536. WSAPI_ErrorCode WSAPI_GetIndexedParameter (WSAPI_CommandPBPtr pb, WSAPI_ParamKeywords whichParam, 
  537.                                     WSAPI_IndexStringPtr index, WSAPI_DescPtr *descriptor);
  538. /*    ## Use this routine to obtain descriptors that reference indexed items in a named server data element. 
  539.     These elements consist of values with repeating items that are specified by a unique index value
  540.     for each item. Attempting to use this routine on a non-indexed parameter will simply return the
  541.     value of the scalar parameter. The index selector is case-insensitive. pb may be null when appropriate.
  542.     
  543.     You must always dispose of any descriptors returned by WSAPI_GetIndexedParameter.
  544.     
  545.     If the value for a parameter is undefined at the time the call is made, but the parameter is a legal
  546.     one to request, WSAPI_GetIndexedParameter will return WSAPI_E_RequestFailed. If the parameter cannot be 
  547.     requested at the time the call is made (because of role or message conflicts), the WSAPI_E_WrongRoleForCall 
  548.     error will be returned.
  549.     
  550. */
  551.  
  552.  
  553. WSAPI_ErrorCode WSAPI_SetIndexedParameter (WSAPI_CommandPBPtr pb, WSAPI_ParamKeywords whichParam, 
  554.                                     WSAPI_IndexStringPtr index, WSAPI_DescPtr descriptor);
  555. /*    ## Use this routine to set indexed items of server elements to the value specified in the descriptor.
  556.     You need to create the descriptor first, using WSAPI_NewDescriptor. Then use WSAPI_SetDescriptor
  557.     to insert values into the new descriptor before passing it to WSAPI_SetIndexedParameter.
  558.     Attempting to use this routine on a non-indexed parameter will simply set the
  559.     value of the scalar parameter. The index selector is case-insensitive. pb may be null when appropriate.
  560. */
  561.  
  562. WSAPI_ErrorCode WSAPI_NewDescriptor (WSAPI_CommandPBPtr pb, WSAPI_DescPtr *descriptor, 
  563.                                         OSType dataType, void *data, unsigned long dataSize);
  564.  
  565. /*  Pass a pointer to a descriptor pointer and WSAPI will allocate it, defining the data type, size and content. 
  566.     If the data pointer is null when passed, a data block of dataSize will be allocated anyway and you
  567.     can assign values to the descriptor later using WSAPI_SetDescriptor. If you supply data storage and pass
  568.     it in the data parameter, you are responsible for deallocating the storage later. If you pass NULL, the
  569.     data is allocated and deallocated by WSAPI automatically.
  570. */
  571.  
  572. WSAPI_ErrorCode WSAPI_DisposeDescriptor (WSAPI_CommandPBPtr pb, WSAPI_DescPtr *descriptor);
  573.  
  574. /*  Pass a pointer to a descriptor pointer that needs deallocation and WSAPI will deallocate it.
  575. */
  576.  
  577. WSAPI_ErrorCode WSAPI_GetDescriptor (WSAPI_CommandPBPtr pb, WSAPI_DescPtr descriptor, 
  578.                                         OSType *dataType, void *data, unsigned long *dataSize);
  579. /*  Pass a descriptor pointer and WSAPI will return specific information about the descriptor. You 
  580.     must provide storage for all pointers. The data pointer must be large enough to hold the number of
  581.     bytes returned in the dataSize parameter. If the data pointer is NULL, WSAPI still returns the type
  582.     and size information, allowing you to then allocate an appropriately sized data container and 
  583.     call WSAPI_GetDescriptor again with a non-null data pointer. When called, dataSize should be initialized
  584.     to the maximum size of your data buffer. On return, it will contain the actual amount of data stored
  585.     in the data buffer.
  586. */
  587.  
  588.  
  589. WSAPI_ErrorCode WSAPI_SetDescriptor (WSAPI_CommandPBPtr pb, WSAPI_DescPtr descriptor, 
  590.                                     void *data, unsigned long dataSize);
  591. /*  Sets the data and size portions of an existing descriptor pointed to by "descriptor".
  592.     Data is copied from the "data" parameter into the storage allocated inside the descriptor.
  593.     If the existing data area allocated inside the descriptor is too small, the server will attempt
  594.     to resize it to be large enough for dataSize bytes of data. But your plug-in should be prepared
  595.     to handle a failure if the storage cannot be resized.
  596. */
  597.  
  598. WSAPI_ErrorCode WSAPI_RegisterAction (WSAPI_CommandPBPtr pb, char *actionTag, char *pluginName);
  599. /*     Your plug-in must call this routine in response to the WSAPI_Register message in order to 
  600.     define an action that allows WebSTAR to call your plug-in. These actions are temporary and
  601.     only exist while your plug-in is active. actionTag is the name of the action that will
  602.     show up in Admin's transfer type pop-up. pluginName is a string that names your code
  603.     fragment. Both values should be unique among all plug-ins and may be the same value.
  604. */
  605.  
  606. WSAPI_ErrorCode WSAPI_RegisterSuffix (WSAPI_CommandPBPtr pb, char *actionTag, char *suffix,
  607.                                         OSType fileType, OSType creatorType, char *mimeType);
  608. /*    Your plug-in can call this routine in response to the WSAPI_Register message in order to 
  609.     define suffix mappings that allows the server will use with your plug-in. 
  610.     These suffix mappings are temporary and only exist while your plug-in is active. 
  611.     actionTag is the name of the action that will be invoked when a given suffix mapping
  612.     show up in Admin's transfer type pop-up. The suffix parameter is the string that the server
  613.     will match (e.g., ".html") to invoke the specified action.
  614.     The next two fields are machine-specific and make sense on Macs only. The last parameter is
  615.     the MIME type to send with this transfer.
  616. */
  617.  
  618. WSAPI_ErrorCode WSAPI_RegisterAccessControl (WSAPI_CommandPBPtr pb);
  619. /* ## By making this call, your plug-in is registered as a handler for access control checks. There
  620.     may be more than one access control handler. Your plug-in will receive a WSAPI_AccessControl message
  621.     when appropriate. You should evaluate the URL and any other information necessary to determine whether or 
  622.     not access should be granted. Fill in the accessControl parameter block fields accordingly. If accessGranted 
  623.     is false, the server will refuse to allow access to that URL and if authRequired is true, it will return an
  624.     appropriate HTTP response to cause the client to prompt for a username and password.
  625.     Note that you are running as a "pre-" preprocessor and should not attempt to access data from the HTTP stream
  626.     or otherwise manipulate information that may affect subsequent processing of the URL. Also, the first
  627.     access control plug-in to refuse access terminates the access control checks, so it's not always the case
  628.     that you will receive every WSAPI_AccessControl message, especially if there are other access control
  629.     handlers installed before yours.
  630. */
  631.  
  632. WSAPI_ErrorCode WSAPI_RegisterFilter (WSAPI_CommandPBPtr pb);
  633. /* ## By making this call, your plug-in is registered as a filter for incoming HTTP requests. You will be
  634.     sent the WSAPI_Filter message and a PB structure (WSAPI_FilterPB) that contains a pointer to the complete
  635.     HTTP request and its length. This includes all header info up to and including the CRLF CRLF separator between
  636.     the HTTP request and the HTTP object body (if any).
  637.     
  638.     You will receive this message BEFORE the server has interpreted the contents of the HTTP request. 
  639.     You may read any info you'd like from this request buffer, but may not modify its contents. 
  640.     You may also create a new buffer using WSAPI_AllocateMemory and populate it with a new HTTP
  641.     request to be interpeted by the server. Since multiple filters may be installed, there is no guarantee what
  642.     order you will be called in or whether or not subsequent modifications will be made to the request you generate.
  643.     By setting the newRequest field to a value other than null, you inform the server that it should use your
  644.     request instead of the one received from the client. You MUST create a legal HTTP 1.0 request header and
  645.     include the CRLF CRLF separator at the end of the request.
  646.     The server is responsible for deallocating this new request buffer when done.
  647. */
  648.  
  649. /*********************/
  650. /* security services */
  651.  
  652. WSAPI_ErrorCode WSAPI_ValidateUser (char *name, char *passwd, char *realm);
  653. /*    Using the piUserKeyword, piPasswordKeyword, and piCurrentRealm fields, you can validate whether or not a specific
  654.     user should be allowed access. You may substitute your own values in place of any of the predefined parameters
  655.     if desired. (e.g., pass your own realm string instead of checking only for the current realm.)
  656.     
  657.     Returns WSAPI_I_NoErr if the user, password, and realm are OK. Returns WSAPI_I_NoPermission if the validation
  658.     fails for any reason. Note that this call will return WSAPI_E_MessageNotHandled if an external function is
  659.     providing security controls for the server (e.g., a security plug-in).
  660. */
  661.  
  662. /*************************/
  663. /** AppleEvent Services **/
  664.  
  665. // routines for registering event handlers, sending events, etc.
  666.  
  667. WSAPI_ErrorCode WSAPI_SendIPCMessage (WSAPI_CommandPBPtr pb, void *msg);
  668. /*    Sends an async, platform-specific interprocess communication message (e.g., AppleEvent on a Mac) that your
  669.     plug-in has already constructed. For Mac O/S, pass a pointer to the AppleEvent structure you wish to send.
  670.  
  671.     IMPORTANT for WebSTAR Mac plug-ins!!!! 
  672.     For WebSTAR plug-ins, the server generates the appropriate return ID for your AppleEvent, so the value you
  673.     supply to the AECreateAppleEvent call will be overwritten. If you are making this call as part of processing a
  674.     message other than "Run" (i.e., that is NOT associated with a HTTP connection), you should note that your
  675.     plug-in can have at most one pending event because ALL of your other message handlers run in a separate context 
  676.     from a HTTP connection and share a single return ID that WebSTAR uses to connect the asynch event reply to your
  677.     plug-in.
  678.     
  679.     You are responsible for disposing any platform-specific data associated with your message after it
  680.     has been sent (i.e., the event and address descriptors on Macs).
  681. */
  682.  
  683. WSAPI_ErrorCode WSAPI_WaitForIPCReply (WSAPI_CommandPBPtr pb, WSAPI_IPC_ResultPtr *msg);
  684. /*    If you send an interprocess communication message (e.g., an AppleEvent under Mac O/S) and expect
  685.     and asynchronous reply received by and delivered through the server to your thread of execution, you
  686.     should call this routine once you expect the reply (i.e., after you've sent the IPC message). If the
  687.     server receives the message reply before the timeout period defined by the server, your reply will be
  688.     returned in the msg parameter. If not, msg will be null and an error code will be returned by the function.
  689.     
  690.     IMPORTANT for WebSTAR Mac plug-ins!!!! 
  691.     When the AppleEvent is returned to you, you MUST resume the AppleEvent with a call to AEResumeTheCurrentEvent.
  692.     (See IM VI, 6-84) This will pass control to the handler you specify (should be a UPP to a procedure in your 
  693.     plug-in.) The handler must process the AE to completion. It is VERY important that your plug-in do this in
  694.     a timely fashion and NOT yield time to other threads. (Well, yielding seems like a bad thing at this point
  695.     because it might allow another plug-in to begin processing an event in parallel, and the AE manager is NOT
  696.     reentrant and cannot process 2 events at once!) This means no callbacks until the event is handled!
  697.     
  698.     If msg is not null, you are responsible for disposing the msg data structure, plus any data passed to 
  699.     you in it if necessary.
  700. */
  701.  
  702. /*************************/
  703. /**  Logging Services   **/
  704.  
  705. //TBS - routines for making log entries, processing log data, etc.
  706.  
  707. WSAPI_ErrorCode WSAPI_WriteLogEntry (WSAPI_CommandPBPtr pb, char *pluginName, char *msg);
  708. /*    Writes the contents of msg to the server's log file. msg should be a null terminated
  709.     C string. pluginName is a C string (generally your plug-in's name) that will prefix the log entry.
  710.     The combined length of pluginName and msg should be less than 510 characters.
  711. */
  712.  
  713.  
  714. /*************************/
  715. /** Status Msg Services **/
  716.  
  717. WSAPI_ErrorCode WSAPI_DisplayMessage (WSAPI_CommandPBPtr pb, char *msg);
  718. /*    
  719.     Writes the contents of msg on the server's status window. msg should be a null terminated
  720.     C string.
  721. */
  722.  
  723.  
  724. /**************************************/
  725. /** User-supplied dispatcher routine **/
  726.  
  727. WSAPI_ErrorCode WSAPI_Dispatch (WSAPI_CommandPBPtr command);
  728. /*    You must define this routine, which will be called from the WebSTAR Plug-in Framework
  729.     library with a complete WSAPI_CommandPB record passed to your routine.
  730. */
  731.  
  732. #ifdef __cplusplus
  733. }
  734. #endif
  735.  
  736. #if GENERATINGPOWERPC
  737. #pragma options align=reset
  738. #endif
  739.  
  740. #endif